<template>
  <div class="audition248">
    <p>1. 数组去重</p>
    <v-md-preview :text="text1" />
    <p>2. 找出数组中重复次数最多的值</p>
    <v-md-preview :text="text2" />
    <p>3. 将二维数组转换为一维数组</p>
    <v-md-preview :text="text3" />
    <p>4. 求数组中的最大值最小值</p>
    <v-md-preview :text="text4" />
  </div>
</template>

<script>
const prefix = '``` js'
const suffix = '```'
export default {
  name: 'Audition248',
  data() {
    return {
      text1: `${prefix}
      var arr = [1, 2, 2, 5, 10, 1, 8, 5]
      var newArr = arr.reduce((a, b) => {
        !a.inclueds(b) && a.push(b)
        return a
      }, [])
      console.log(newArr)
      \n${suffix}`,
      text2: `${prefix}
      var obj = arr.reduce((a, b) => {
        a[b]++ || (a[b] = 1)
        return a
      }, {})
      console.log(obj)
      \n${suffix}`,
      text3: `${prefix}
      var newArr = arr.reduce((a, b) => {
        if(Array.isArray(b)) {
          a = a.concat(b)
        } else {
          a.push(b)
        }
        return a
      }, [])
      console.log(newArr)
      \n${suffix}`,
      text4: `${prefix}
      // 求最大值
      var maxNum = arr.reduce((a, b) => {
        return Math.max(a, b)
      })
      // 求最小值
      var minNum = arr.reduce((a, b) => {
        return Math.min(a, b)
      })
      \n${suffix}`,
    }
  }
}
</script>

<style>

</style>